Scripting Solutions

This topic contains a number of actual solutions using Lua Scripting in Q-SYS Designer.

Radio Buttons

In Q-SYS Designer there are a number of places that have a group of toggle type buttons that operate independently. For example, the Mixer Solo buttons. At times you may find a reason to have these buttons act like radio buttons. With the following script, you can make a group of toggle type buttons into radio buttons, allowing only one button active at a time. The Control Pin outputs of the buttons in the group connect to the Script inputs. In this example the Solo buttons normally act independently, with the script, they now function like radio buttons.

Radio Button Script

-- Radio Buttons, turn off all but the control that changed

function exclude( ctl )

if ctl.Value == 1 then

for i, c in ipairs( Controls.Inputs ) do

if c ~= ctl then

c.Value = 0

end

end

end

end

-- assign function to control change

 

for ix, ctl in ipairs( Controls.Inputs ) do

ctl.EventHandler = exclude

end

Select Loudest of Two Signals

This script is designed to switch a router to the loudest of two microphone inputs. If a person had two microphones and was moving between the two, this the microphone used is closest to the person speaking. The script can be modified to accept more inputs, and the inputs do not have to be microphones.

Select Loudest of Two Signals Script

-- Switch router to signal with greatest level --

cin_meter1 = Controls.Inputs[1]

cin_meter2 = Controls.Inputs[2]

cout_select = Controls.Outputs[1]

 

-- Compare two values and switch a router to the greater

 

CompTimer.EventHandler = function()

if cin_meter1.Value > cin_meter2.Value then

cout_select.Value = 1

else

cout_select.Value = 2

end

end

 

-- Every .5 seconds, run comparison

 

CompTimer = Timer.New()

Timer:Start( .5 )

Buttons to Select and Play Audio File

The default method of selecting an audio file to play is to use the drop-down list in the Audio Player. This script allows you to select and play a file by pushing a button.

Buttons to Select and Play Audio File Script

-- Play specified files

-- NOTE: The number of trigger inputs to this script can be

-- changed without changing the script

 

files = {

"A.wav",

"B.wav",

"C.wav"

}

 

cout_file = Controls.Outputs[1]

cout_play = Controls.Outputs[2]

 

function play( ctl )

print( "play: "..files[ctl.Index] )

cout_file.String = files[ctl.Index]

cout_play:Trigger()

end

 

for i,c in ipairs( Controls.Inputs ) do

c.EventHandler = play

end

Button to Send Text String to Simple TCP/IP Socket

When a user presses a button, this script connects, sends a text string, and then disconnects.

Button to Send Text String to Simple TCP/IP Socket Script

The following script connects to the localhost IP address 127.0.0.1 on port 8080 and sends the message "this is a message" using TCP/IP. This example demonstrates the Event/EventHandler model: BeginConnect initiates the connection, the connection event callback is to OnConnect which calls BeginSend. The BeginSend callback is to OnSend, which displays either a success or failure message to the Lua console window.

local ipAddress = "127.0.0.1"

local port = 8080

local message = "this is a message"

local socket = TcpSocket.New()

 

function OnSend(async)

e = socket:EndSend(async)

if e then

print( "Error sending " ..e )

else

print( "Send OK" );

end

socket:Close()

end

 

function OnConnect(async)

e = socket:EndConnect(async)

if e then

print( "Error connecting ".. e )

else

socket:BeginSend( message, OnSend )

end

end

 

socket:BeginConnect(ipAddress, port, OnConnect)

Serial Port (RS-232) Control Script

This sample code activates the Play or Stop function on a TASCAM® DVD player. Details of the commands and checksum are taken from the TASCAM® DVD Player user manual. This is used in conjunction with the RS-232 Serial Port and Custom Controls components.

Serial Port Control Script for TASCAM® DVD Player

ser = SerialPorts[1]

 

playMessage = string.char(0x02)..">PLYcFWD 17"..string.char(0x03) --Command to press 'play'

stopMessage = string.char(0x02)..">STPc 98"..string.char(0x03) --Command to press 'stop'

 

function play()

ser:Write(playMessage)

print(“Sent Play: “..playMessage)

end

 

function stop()

ser:Write(stopMessage)

print(“Sent Stop: “..stopMessage)

end

 

ser.EventHandler = function( port, msg )

if msg == SerialPorts.Events.Connected then

print("Serial port connected")

elseif msg == SerialPorts.Events.Data then

print( "Response: "..port:ReadLine(SerialPorts.EOL.Custom, string.char(0x03) ))

end

end

 

ser:Open(9600)

Controls.Inputs[1].EventHandler = play

Controls.Inputs[2].EventHandler = stop

Related Topics Link IconRelated Topics


 

© 2009 - 2016 QSC, LLC. All rights reserved. QSC and the QSC logo are trademarks of QSC, LLC in the U.S. Patent and Trademark office and other countries. All other trademarks are the property of their respective owners.

http://patents.qsc.com.